from .models import CourseCategory, Course, Teacher
from rest_framework import serializers


class TeacherSerializer(serializers.ModelSerializer):
    class Meta:
        model = Teacher
        fields = '__all__'


class CourseCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = CourseCategory
        fields = ['id', 'name']


class CourseSerializer(serializers.ModelSerializer):
    # 因为返回的teacher只是一个主键id，不是对象，
    # 所以我们还得对其进行序列化
    teacher = TeacherSerializer()

    class Meta:
        model = Course
        fields = ["id", "name", "course_img", "students", "lessons", "pub_lessons",
                  "price", "real_price", "discount_name", "teacher", "lesson_list"]


class CourseRetrieveSerializer(serializers.ModelSerializer):
    teacher = TeacherSerializer()

    class Meta:
        model = Course
        fields = ["id", "name", "course_img", "students", "lessons", "pub_lessons", 'real_brief',
                  "price", "real_price", "discount_name", "teacher", "lesson_list", 'level_name',
                  "chapter_list"]


